const { addrFormatError } = require('../constant/error.type')

const validator = rules => {
  return async (ctx, next) => {
    try {
      ctx.verifyParams(rules)
    } catch (error) {
      console.log('地址参数格式错误', error)
      addrFormatError.result = error.errors
      return ctx.app.emit('error', addrFormatError, ctx)
    }

    await next()
  }
}

module.exports = { validator }
